/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   04.05.2010
 * @version SVN: $Id: IpConfigForm.java 168 2010-05-24 09:58:44Z f.aarndt@web.de $
 */

package org.cakis.client.forms;

import javax.microedition.lcdui.TextField;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;

import org.cakis.client.CakisMIDlet;
import org.cakis.client.commands.IpConfigCommand;

/**
 * IpConfigForm
 * 
 * @author Florian Arndt
 */
public class IpConfigForm extends AbstractForm {
	private TextField ipAddress;

	public IpConfigForm(CakisMIDlet midlet) {
		super("Konfiguration", midlet);
		try {
			RecordStore ipStore = RecordStore.openRecordStore("ipStore", false);
			ipAddress = new TextField("WebService IP: ", new String(ipStore
					.getRecord(1)).trim(), 256, TextField.ANY);
			System.out.println(new String(ipStore.getRecord(1)).trim());
			ipStore.closeRecordStore();
		} catch (RecordStoreFullException e) {
			e.printStackTrace();
		} catch (RecordStoreNotFoundException e) {
			ipAddress = new TextField("WebService IP: ", "192.168.178.28", 256,
					TextField.ANY);
			e.printStackTrace();
		} catch (RecordStoreException e) {
			ipAddress = new TextField("WebService IP: ", "192.168.178.28", 256,
					TextField.ANY);
			e.printStackTrace();
		}

		this.append(ipAddress);
		this.addCommand(new IpConfigCommand(midlet, ipAddress));
		midlet.display(this);
	}
}
